package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.witchdraw.config.WitchDrawConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.witchdraw.WitchDrawMgr;

import java.util.ArrayList;
import java.util.List;

public class WitchDrawRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = WitchDrawMgr.getActivityInfo();

        if (ActivityMgr.activityInShowTime(activityInfo)) {
            long recycleTime = activityInfo.getEndShowTime() * 1000L + gapTime;
            WitchDrawConfig config = WitchDrawMgr.getConfig();
            if (config != null) {
                int itemId = config.getDrawItemId();
                int tokenItem1 = config.getTokenItem1();
                int tokenItem2 = config.getTokenItem2();
                int tokenItem3 = config.getTokenItem3();
                ActivityItemRecycleMgr.addRecycleItemData(itemId,activityType,1,recycleTime, new ArrayList<>());
                ActivityItemRecycleMgr.addRecycleItemData(tokenItem1,activityType,1,recycleTime, new ArrayList<>());
                ActivityItemRecycleMgr.addRecycleItemData(tokenItem2,activityType,1,recycleTime, new ArrayList<>());
                ActivityItemRecycleMgr.addRecycleItemData(tokenItem3,activityType,1,recycleTime, new ArrayList<>());
            }
        }

    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.WitchDraw.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1){
            UserBagItem item = getUserBagItem(userId, data.getItemId());
            if (item != null && item.getNum() > 0) {
                removeItem(item);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
